<template>
  <div class>
    <h5 class="titleInfo">医院评价</h5>
    <el-form label-width="130px" ref="params" :rules="rules" :model="params">
      <el-row>
        <el-col :span="24">
          <el-form-item label="项目编号" prop="projectId">
            <el-select filterable placeholder="请选择" @change="selectfn" v-model="params.projectId">
              <el-option
                v-for="item in project"
                :key="item.projectId"
                :label="item.name"
                :value="item.projectId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="项目评分" prop="projectStar">
            <span class="spanToInput">
              <div style="padding-top: 10px;">
                <el-rate v-model="params.projectStar"></el-rate>
              </div>
            </span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="项目图片">
            <!-- this.form.projectImages = this.$refs.uploadImg2.submitUpload();-->

            <!-- <newUpload
              ref="uploadImg1"
              :file-num="fileNum1"
              :file-list="fileList1"
              :width="imgWeith1"
              :height="imgHeight1"
            />-->
            <div class="newbox">
              <div class="newimg" v-for="(item, index) in fileList1" :key="index">
                <img :src="item.url" alt />
                <span @click="close(index, 1)">X</span>
              </div>

              <imgload :width="216" :height="216" @imgfun="imgfun"></imgload>
            </div>

            <p>图片尺寸216*216px</p>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目评价" prop="projectContents">
            <div style="padding-top: 10px;">
              <el-input
                type="textarea"
                :rows="2"
                v-model="params.projectContents"
                placeholder="请输入内容最大不超过300"
                :maxlength="300"
              ></el-input>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
const vaildateStart = (rule, value, callback) => {
  if (!value) {
    callback(new Error("不能低于一星"));
  } else {
    callback();
  }
};
import imgload from "@/components/tailoring/index";
export default {
  components: { imgload },
  props: {
    project: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      rules: {
        projectId: [
          {
            required: true,
            message: "项目不能为空",
            trigger: "blur"
          }
        ],
        projectStar: [
          {
            validator: vaildateStart,
            trigger: "blur"
          }
        ],
        projectImgList: [
          {
            required: true,
            message: "项目评价图片不能为空",
            trigger: "blur"
          }
        ],
        projectContents: [
          {
            required: true,
            message: "项目评价不能为空",
            trigger: "blur"
          }
        ]
      },
      value1: 0,
      fileList1: [],
      fileNum1: 5,
      params: {}
    };
  },
  methods: {
    checkfn() {
      let abc = "";
      let arr = [];
      this.fileList1.map(res => {
        arr.push(res.url);
      });
      this.params.projectImgList = arr;
      
      this.$refs["params"].validate(valid => {
        console.log(123, valid);
        if (valid && this.params.projectImgList.length) {
          abc = true;
        } else {
          this.$message({
            message: this.params.projectImgList.length?"请完善信息再提交":'请上传项目图片',
            type: "warning"
          });
          abc = false;
        }
      });
      return abc;
    },
    selectfn(val) {
      // console.log(val,this.list)
      let arr = this.project.filter(res => {
        return res.projectId == val;
      });
      this.params.projectName = arr[0].name;
    },
    imgfun(res) {
      console.log(res);

      //  this.form.logo = res;
      if (this.fileNum1 == this.fileList1.length) {
        this.fileList1.splice(this.fileList1.length - 1, 1);
      }

      this.fileList1.push({
        url: localStorage.getItem("imgUrlPrefix") + res
      });

      console.log(this.fileList1);
    },
    close(index, type) {
      if (type == 1) {
        this.fileList1.splice(index, 1);
      }
    }
  }
};
</script>
<style scoped>
.newbox {
  position: relative;
  display: flex;
  align-items: center;
}
.newbox /deep/ .footerBtn {
  height: 34px;
  margin-left: 22px;
}
.newimg {
  width: 148px;
  height: 148px;
  margin-left: 25px;
  position: relative;
}
.newimg img {
  width: 100%;
  height: 100%;
}
.newimg span {
  position: absolute;
  font-size: 15px;
  right: 6px;
  top: 0;
  cursor: pointer;
}
.app-container {
  padding: 0px !important;
}
</style>
